import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);

// 不需权限就可访问
export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index'),
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
  },
  {
    path: '/noAuth',
    name: 'noAuth',
    component: () => import('@/views/noAuth'),
  },
];

// 需要权限才能访问
export const asyncRoutes = [
  {
    path: '/',
    redirect: '/index',
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('@/views/organization'),
    meta: { title: '组织架构' },
  },
  {
    path: '/position',
    name: 'position',
    component: () => import('@/views/position'),
    meta: { title: '岗位管理' },
  },
  {
    path: '/positionLevel',
    name: 'positionLevel',
    component: () => import('@/views/positionLevel'),
    meta: { title: '岗位级别' },
  },
  {
    path: '/info',
    name: 'info',
    component: () => import('@/views/info'),
    meta: { title: '我的企业' },
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
];

function createRouter() {
  return new Router({
    routes: [...constantRoutes, ...asyncRoutes],
  });
}

const router = createRouter();

export function resetRouter() {
  router.matcher = createRouter().matcher;
}

export default router;
